<script>
    function mlcurrying(fn, ...args1) {
        let length = fn.length;
        let allArgs = [...args1];
        let res = (...args2) => {
            allArgs = [...allArgs, ...args2]
            if (allArgs.length == length) {
                return fn(...allArgs)
            }else{
                return res;
            }
        }
        return res;
    }

    // 测试：
    const add = (a, b, c) => a + b + c;
    const a = mlcurrying(add, 1);
    console.log(a(2, 3))  // 6

    const b = mlcurrying(add, 1, 2, 3);
    console.log(b())  // 6

    const c = mlcurrying(add);
    console.log(c(1, 2, 3))  // 6

    const d = mlcurrying(add, 1)
    console.log(d(2)(3));  // 6
</script>